<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://localhost:3000/socket.io/socket.io.js"></script>

    <script>
        var scoket = io('http://localhost:3000/');//和服务器建立连接
        window.onload = function(){
            let btn  = document.getElementById('btn');
            btn.onclick =function(){
                scoket.emit('addcart',{
                    client:'these are datas from client-side'
                });
            };
            //监听服务器的广播
            scoket.on('to-client',function(data){
                console.log(data);
            });

        }
    </script>
</head>
<body>
<button id="btn">向服务器发送请求</button>
</body>
</html>